package com.hnqcgczy.dao.imp;

import com.hnqcgczy.dao.BaseDao;
import com.hnqcgczy.dao.ICategoryDao;
import com.hnqcgczy.db.MyTransaction;
import com.hnqcgczy.vo.TProductCategory;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CategoryDaoImpl extends BaseDao implements ICategoryDao {
    MyTransaction myTransaction;
    public CategoryDaoImpl(MyTransaction myTransaction){
        //实现BaseDao初始化
        super(myTransaction);
       this.myTransaction=myTransaction;
   }

    @Override
    public List<TProductCategory> getCategoryList() throws SQLException {
        //limit 查询前多少条
        String sql="select * from t_product_category";
        //调用basedao 完成查询,返回结果集
        ResultSet rs=this.query(sql);
//        //将返回结果集映射为List集合
        List<TProductCategory> list=new ArrayList<TProductCategory>();
        if(rs!=null){
            while(rs.next()){
                TProductCategory category=new TProductCategory();
                category.setTpcId(rs.getInt("tpc_id"));
                category.setTpcName(rs.getString("tpc_name"));
                category.setTpcParentId(rs.getInt("tpc_parent_id"));
                //将映射的product对象存入集合
                list.add(category);
            }
        }
        this.closeResource();
        return list;


    }
}
